import { t } from "../../i18n/index"
import { phoneNumRule, phoneNumRuleSimple } from "../common"
import type { FormRules } from 'element-plus'
import {validateChineseLength} from "../../util/util"
// 表单数据格式
export class FormDataType {
    customerName: string = "" // 客户姓名
    phoneNumber: string = "" // 客户手机号
    storeTypeIndustryId: number[] = [] // 店铺类型/行业ID
    enterpriseName: string = "" // 企业名称
    contactPerson: string = "" // 联系人
    contactPersonPhone: string = "" // 联系人电话
    customerAddress: string = "" // 客户地址
    customerAddressId: string[] = [] // 客户地址
    customerAddressDetail: string = "" // 详细地址
    remark: string = "" // 备注

    customerId: string = "" // 客户ID
    originalPhone: string = "" // 原始客户电话
    storeTypeIndustry: string = "" // 店铺类型/行业
    pageIndex: number = 0
    pageSize: number = 0
}

export class submitDataType {
    customerName: string = "" // 客户姓名
    phoneNumber: string = "" // 客户手机号
    storeTypeIndustryId: string = "" // 店铺类型/行业ID ----
    enterpriseName: string = "" // 企业名称
    contactPerson: string = "" // 联系人
    contactPersonPhone: string = "" // 联系人电话
    customerAddress: string = "" // 客户地址 ----
    customerAddressId: string = "" // 客户地址 ----

    customerAddressDetail: string = "" // 详细地址
    remark: string = "" // 备注

    customerId: string = "" // 客户ID
    originalPhone: string = "" // 原始客户电话
    storeTypeIndustry: string = "" // 店铺类型/行业
    pageIndex: number = 0
    pageSize: number = 0
}

// 线索来源数据格式
export interface SelectDataType {
    title: string
    code: string
}


// 表单的校验规则
export const formDataRules: FormRules<FormDataType> = {
    customerName: [
        { required: true, message: t('clueInformation_customerMoniker_placeholder'), trigger: 'blur' },
        {
            validator: function (rule: any, value: any, callback: any) {
                if (!value) {
                    return callback(new Error(t("clueInformation_Sector_placeholder")))
                } else {
                    if (!validateChineseLength(value.trim())) {
                        return callback(new Error(t("customerInfoMation_customerName_maxLength")))
                    } else {
                        callback()
                    }
                }
            }, trigger: "blur"
        }
    ],
    phoneNumber: phoneNumRule,
    storeTypeIndustryId: [
        { required: true, message: t("clueInformation_Sector_placeholder"), trigger: "blur" }
    ],
    enterpriseName: [
        { required: true, message: t("customerInfoMation_nameOfAffiliatedEnterprise_placeholder"), trigger: "blur" }
    ],
    contactPersonPhone: phoneNumRuleSimple
}


export type IndustryDataType = IndustryItemDataType[]


export interface IndustryItemDataType {
    industryId: number
    parenId: number
    industryName: string
    level: number
    industryOrder: number
    children: Array<Children>
}

export interface Children {
    industryId: number
    parenId: number
    industryName: string
    level: number
    industryOrder: number
    children?: Array<any>
}
